﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Kojarskiy.Core
{
    public class ContentBlock
    {
        public string Name { get; set; }
        public int Column { get; set; }
        public int Row { get; set; }
        public int SizeX { get; set; }
        public int SizeY { get; set; }
        public string Type { get; set; }

        public static List<ContentBlock> ParseLayout(string data)
        {
            var blocks = new List<ContentBlock>();
            if (!string.IsNullOrEmpty(data))
            {
                var layoutItems = data.Split('&');

                for (int i = 0; i < layoutItems.Count() / 10; i++)
                {
                    var contentBlock = new ContentBlock()
                    {
                        Column = Convert.ToInt32(layoutItems[i * 10 + 1].Substring("value=".Length)),
                        Row = Convert.ToInt32(layoutItems[i * 10 + 3].Substring("value=".Length)),
                        SizeX = Convert.ToInt32(layoutItems[i * 10 + 5].Substring("value=".Length)),
                        SizeY = Convert.ToInt32(layoutItems[i * 10 + 7].Substring("value=".Length)),
                        Type = layoutItems[i * 10 + 9].Substring("value=".Length)
                    };
                    blocks.Add(contentBlock);
                }
            }
            return blocks;
        }
        public static string GetNameByType(string type)
        {
            switch (type)
            {
                case "Text":
                    return "Текстовый блок";
                case "Content":
                    return "Контент страницы";
                case "Popular":
                    return "Популярные товары";
                case "Menu":
                    return "Блок меню";
                case "Filter":
                    return "Фильтр товаров";
                case "Action":
                    return "Акции";

            }
            return "Блок";
        }
    }
}